package org.example.java8.stream;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.IntSummaryStatistics;
import java.util.List;
import java.util.stream.Collectors;

public class Test {

	public static void main(String[] args) {
		
		List<String> list = new ArrayList();     
		list.add("Tom");
		list.add("Tom");
		list.add("Jack");
		list.add("Lucy");    
		list.add("Jackie");
		
		List<String> list1 = list.stream()
				.filter(x -> x.contains("o"))
				.sorted((x, y) -> x.compareTo(y))
				.distinct()
				.limit(3)
				.collect(Collectors.toList());

		System.out.println(list1);
		
		
//		List<String> list2 = 
				list.parallelStream()
//				.filter(x -> x.contains("k"))
//				.sorted((x, y) -> x.compareTo(y))
				.map(x -> x+x)
//				.distinct()
				.limit(5)
				.forEach(System.out::println);			
				

		
//		List<String> strings = Arrays.asList("abc", "", "bc", "efg", "abcd","", "jkl");
//		// 获取空字符串的数量
//		long count = strings.stream().filter(string -> string.isEmpty()).count();
//		System.out.println(count);
				
				

		List<Integer> nums = Arrays.asList(1, 2, 3, 3, 4, 4, 5, 6);
		
		IntSummaryStatistics stats = nums.stream()
				.mapToInt(x -> x)
				.summaryStatistics();
		
		System.out.println("最大的数= " + stats.getMax());
		System.out.println("最小的数= " + stats.getMin());
		System.out.println("数的总和= " + stats.getSum());
		System.out.println("平均数= " + stats.getAverage());
		
	}

}
